package com.abou.mvc.controller.admin;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * The controller for the login page
 * 
 * @author khalid
 */
@Controller
public class LoginController {
  
  /**
   * The request mapping for login view
   */
  public static final String LOGIN_VIEW_REQUEST_MAPPING = "/admin/login.do";
  
  /**
   * The request mapping for login error view
   */
  public static final String LOGIN_VIEW_ERROR_REQUEST_MAPPING =
      "/admin/login-error.do";
  
  /**
   * The login view
   */
  public static final String LOGIN_VIEW = "admin/login";
  
  /**
   * The login error view
   */
  public static final String LOGIN_PWD_FORGOTTEN_ERROR_PATH =
      "login-pwd-error.do";
  
  /**
   * The login error attribute
   */
  public static final String LOGIN_ERROR_ATT = "loginError";
  
  /**
   * The password forgotten error attribute
   */
  public static final String PWD_FORGOTTEN_ERROR_ATT = "pwdForgottenError";
  
  /**
   * Shows the login page
   * 
   * @return The name of the view to display
   */
  @RequestMapping(LOGIN_VIEW_REQUEST_MAPPING)
  public String login() {

    return LOGIN_VIEW;
  }
  
  /**
   * Shows the login page in the login error mode
   * 
   * @param model The model
   * @return The name of the view to display
   */
  @RequestMapping(method = RequestMethod.GET, value = "/login-error.do")
  public String loginError(ModelMap model) {

    model.put(LOGIN_ERROR_ATT, "1");
    
    return LOGIN_VIEW;
  }
  
  /**
   * Shows the login page in the password forgotten error mode
   * 
   * @param model The model
   * @return The name of the view to display
   */
  @RequestMapping(method = RequestMethod.GET, value = LOGIN_VIEW_ERROR_REQUEST_MAPPING)
  public String loginPwdForgotten(ModelMap model) {

    model.put(PWD_FORGOTTEN_ERROR_ATT, "1");
    
    return LOGIN_VIEW;
  }
}
